{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#!/usr/bin/env python\n",
    "# -*- coding: utf-8 -*-\n",
    "\n",
    "'''\n",
    "Models for user, blog, comment.\n",
    "'''\n",
    "\n",
    "import time, uuid\n",
    "\n",
    "from transwarp.db import next_id\n",
    "from transwarp.orm import Model, StringField, BooleanField, FloatField, TextField\n",
    "\n",
    "class User(Model):\n",
    "    __table__ = 'users'\n",
    "\n",
    "    id = StringField(primary_key=True, default=next_id, ddl='varchar(50)')\n",
    "    email = StringField(updatable=False, ddl='varchar(50)')\n",
    "    password = StringField(ddl='varchar(50)')\n",
    "    admin = BooleanField()\n",
    "    name = StringField(ddl='varchar(50)')\n",
    "    image = StringField(ddl='varchar(500)')\n",
    "    created_at = FloatField(updatable=False, default=time.time)\n",
    "\n",
    "class Blog(Model):\n",
    "    __table__ = 'blogs'\n",
    "\n",
    "    id = StringField(primary_key=True, default=next_id, ddl='varchar(50)')\n",
    "    user_id = StringField(updatable=False, ddl='varchar(50)')\n",
    "    user_name = StringField(ddl='varchar(50)')\n",
    "    user_image = StringField(ddl='varchar(500)')\n",
    "    name = StringField(ddl='varchar(50)')\n",
    "    summary = StringField(ddl='varchar(200)')\n",
    "    content = TextField()\n",
    "    created_at = FloatField(updatable=False, default=time.time)\n",
    "\n",
    "class Comment(Model):\n",
    "    __table__ = 'comments'\n",
    "\n",
    "    id = StringField(primary_key=True, default=next_id, ddl='varchar(50)')\n",
    "    blog_id = StringField(updatable=False, ddl='varchar(50)')\n",
    "    user_id = StringField(updatable=False, ddl='varchar(50)')\n",
    "    user_name = StringField(ddl='varchar(50)')\n",
    "    user_image = StringField(ddl='varchar(500)')\n",
    "    content = TextField()\n",
    "    created_at = FloatField(updatable=False, default=time.time)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
